package com.example.demo.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.validation.constraints.NotNull;

/**
 * 资金记录表
 * 
 * @author jcong
 *
 * @date: 2018年4月10日 下午7:32:33
 */
@Entity
public class Fund implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5050702722939099691L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long fID; // 资金记录id

	@NotNull
	@Column(columnDefinition = "varchar(100) COMMENT '交易号'")
	private String fundNo;// 交易号

	@Column(columnDefinition = "bigint COMMENT '代理商id'")
	private Long uID; // 代理商id

	@Column(columnDefinition = "int COMMENT '充值方式 1支付宝 2 微信'")
	private Integer fundType;// 充值方式

	@Column(columnDefinition = "varchar(20) COMMENT '交易时间'")
	private String createTime;// 交易时间，毫秒级时间戳，如 1421585369113

	@Column(columnDefinition = "varchar(20) COMMENT '处理时间'")
	private String updateTime;// 处理时间，毫秒级时间戳，如 1421585369113

	@Column(columnDefinition = "int COMMENT '处理状态 0 待审核 1 审核中 2 审核通过 3 审核不通过'")
	private Integer status;// 交易类型
	
	@Column(columnDefinition = "varchar(255) COMMENT '充值订单备注'")
	private String note;// 备注

	@Column(columnDefinition = "varchar(255) COMMENT '处理订单备注'")
	private String withNote;// 备注

	@NotNull
	@Column(columnDefinition = "decimal(10,2) COMMENT '变动金额/充值金额'")
	private Double changeMoney;// 变动资金

	@Column(columnDefinition = "decimal(10,2) COMMENT '变化前金额'")
	private Double beforeMoney;// 变化前金额

	@Column(columnDefinition = "decimal(10,2) COMMENT '变化后金额'")
	private Double afterMoney;// 变化后金额

	@Column(columnDefinition = "int COMMENT '交易类型 0 充值 1 消费 2 退款'")
	private Integer type;// 交易类型

	/**
	 * 充值记录
	 * 
	 * @param fundNo
	 * @param uID
	 * @param nowTime
	 * @param changeMoney
	 * @param beforeMoney
	 * @param afterMone
	 * @return
	 */
	public static Fund buildAccountInpour(String fundNo, long uID, String nowTime, double changeMoney, double beforeMoney,
			double afterMoney) {
		return buildFund(fundNo, uID, nowTime, changeMoney, beforeMoney, afterMoney, 0, 1);
	}

	/**
	 * 订单支付
	 * 
	 * @param fundNo
	 * @param uID
	 * @param nowTime
	 * @param changeMoney
	 * @param originalMoney
	 * @return
	 */
	public static Fund buildPay(String fundNo, long uID, String nowTime, double changeMoney, double beforeMoney,
			double afterMoney) {
		return buildFund(fundNo, uID, nowTime, changeMoney, beforeMoney, afterMoney, 1, 2);
	}

	/**
	 * 订单退款
	 * 
	 * @param fundNo
	 * @param uID
	 * @param nowTime
	 * @param changeMoney
	 * @param originalMoney
	 * @return
	 */
	public static Fund buildRefund(String fundNo, long uID, String nowTime, double changeMoney, double beforeMoney,
			double afterMoney) {
		return buildFund(fundNo, uID, nowTime, changeMoney, beforeMoney, afterMoney, 2, 1);
	}

	public static Fund buildFund(String fundNo, long uID, String nowTime, double changeMoney, double beforeMoney,
			double afterMoney, int type,int status) {
		Fund fund = new Fund();
		fund.setFundNo(fundNo);
		fund.setuID(uID);
		fund.setCreateTime(nowTime);
		fund.setUpdateTime(nowTime);
		fund.setChangeMoney(changeMoney);
		fund.setBeforeMoney(beforeMoney);
		fund.setAfterMoney(afterMoney);
		fund.setType(type);
		fund.setStatus(status);
		return fund;
	}
	

	public Double getBeforeMoney() {
		return beforeMoney;
	}

	public void setBeforeMoney(Double beforeMoney) {
		this.beforeMoney = beforeMoney;
	}

	public Double getAfterMoney() {
		return afterMoney;
	}

	public void setAfterMoney(Double afterMoney) {
		this.afterMoney = afterMoney;
	}

	public Long getfID() {
		return fID;
	}

	public void setfID(Long fID) {
		this.fID = fID;
	}

	public String getFundNo() {
		return fundNo;
	}

	public void setFundNo(String fundNo) {
		this.fundNo = fundNo;
	}

	public Long getuID() {
		return uID;
	}

	public void setuID(Long uID) {
		this.uID = uID;
	}

	public Double getChangeMoney() {
		return changeMoney;
	}

	public void setChangeMoney(Double changeMoney) {
		this.changeMoney = changeMoney;
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public Integer getFundType() {
		return fundType;
	}

	public void setFundType(Integer fundType) {
		this.fundType = fundType;
	}

	public String getWithNote() {
		return withNote;
	}

	public void setWithNote(String withNote) {
		this.withNote = withNote;
	}

	public String getCreateTime() {
		return createTime;
	}

	public void setCreateTime(String createTime) {
		this.createTime = createTime;
	}

	public String getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(String updateTime) {
		this.updateTime = updateTime;
	}

	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}

}
